#!/bin/bash
# backup.sh
# Written by James Kelly <kellyjh@dcs.gla.ac.uk>
# Used with permission.
# Removes stopwords from a file


# $1 This is the full file 
# $2 This is the stopwords file
# $3 This is the output file 



if  [ $# -ne 3 ]; then
    echo "Incorrect number of params";
    exit 1;
fi

exec 3<&0                 # Save stdin to file descriptor 3.
exec 0<"$1"               # Redirect standard input.

line_count=`cat $1 | wc -l `

echo $line_count

for name in `seq $line_count`;  
  do
  read word
  is_stop=`grep -i -x "$word" $2 | wc -l`

  # Error here
  if [ $is_stop -eq  0 ]; then
      echo $word
  fi


done

exec 0<&3                 # Restore old stdin.
exec 3<&-                 # Close temporary fd 3.


exit 0
